package com.kaili.basic.service.impl;/**
 * Created by zengshuai on 18-4-25.
 */

import com.baomidou.mybatisplus.plugins.Page;
import com.kaili.basic.pojo.entity.BaseCustomer;
import com.kaili.basic.pojo.entity.BaseCustomerExport;
import com.kaili.basic.pojo.entity.QueryCustomerVO;
import com.kaili.basic.mapper.BaseCustomerMapper;
import com.kaili.basic.service.BaseCustomerService;
import com.kaili.basic.service.OpenAccountService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zengshuai
 * @Copyright: Copyright (c) 2017
 * @Company: 杭州凯立通信有限公司
 */
@Service
public class BaseCustomerServiceImpl implements BaseCustomerService{

    @Autowired
    BaseCustomerMapper customerMapper;

    @Autowired
    private OpenAccountService openAccountService;


    @Transactional
    @Override
    public int addCustomer(BaseCustomer customer) {
        Integer count = customerMapper.addCustomer(customer);
        Map<String, Object> map=new HashMap<>();
        map.put("accountTypeId",2);
        map.put("dataId",customer.getCustomerId());
        //自动开户
        if(count>0){
            openAccountService.addAccount(map);
            return 1;
        }
        return 0;
    }


    @Override
    public int deleteCustomer(BaseCustomer customer) {
        return customerMapper.deleteCustomer(customer);
    }

    @Override
    public int updateCustomer(BaseCustomer customer) {
        return customerMapper.updateCustomer(customer);
    }


    @Override
    public Page<QueryCustomerVO> queryCustomerDetails(Page<QueryCustomerVO> page,QueryCustomerVO queryCustomerVO) {
        List<QueryCustomerVO> customers = customerMapper.queryCustomerDetails(page,queryCustomerVO);
        return page.setRecords(customers);
    }

    @Override
    public Long getMaxCustomerId() {
        return customerMapper.getMaxCustomerId();
    }

    @Override
    public String getMaxCustomerCode() {
        return customerMapper.getMaxCustomerCode();
    }


    @Override
    public List<BaseCustomer> queryCustomer(BaseCustomer customer) {
        return customerMapper.queryCustomer(customer);
    }

    @Override
    public List<BaseCustomer> queryCustomerCode(@Param("str") String str) {
        return customerMapper.queryCustomerCode(str);
    }

    @Override
    public BaseCustomer getCustomerId(BaseCustomer customer) {
        return customerMapper.getCustomerId(customer);
    }

    @Override
    public List<BaseCustomerExport> queryCustomerExport(Map<String, Object> map) {
        return customerMapper.queryCustomerExport(map);
    }

    @Override
    public List<BaseCustomer> selectCustomer(BaseCustomer customer) {
        return customerMapper.selectCustomer(customer);
    }

}
